<?php
define("_needlogin", "0");
define("_access", "1");
include "../include/db.config.php";
$sql="SELECT category from challenge where enable=1 ";
$res=array();
$res=getAll($sql);
//var_dump($res);
$result=array();
foreach($res as $key => $value){
    $result[]=$value['category'];
}
$result=array_unique($result);
//这里得到所有类别，存在数组里面
//var_dump($result);
$sql="select solves from team where id = {$_SESSION['team']['id']}";
$res=getOne($sql);
$res=json_decode($res['solves']);
//var_dump($res);
//$res=explode(",",$res['solves']);
$current=array();
foreach ($res as $key => $vslues) {
    $sql="select value,category from challenge where id = {$vslues}";
    $current[]=getOne($sql);
}
//var_dump($current);
//这里得到队伍分数以及所属类
$data=array();
foreach($result as $key => $value){
    $data[]['category']=$value;
}
foreach ($current as $key =>$value) {
    foreach($data as $key1 => $values){
        if($value['category']===$values['category']){
            $data["$key1"]['score']+=$value['value'];
        }
    }
}

//var_dump($data);
$total=0;
foreach($data as $key => $value){
    if(!isset($value['score'])){
        $data["$key"]['score']=0;
    }
    $total+=$value['score'];
}
$sql="select value from challenge where enable = 1";
$max=getAll($sql);
$maxscore=0;
foreach($max as $key => $value){
    $maxscore+=$value['value'];
}
$data1['per']=$data;
$data1['tot']=$total;
$data1['max']=$maxscore;
echo json_encode($data1);
